var express = require('express');
var router = express.Router();
var {list} = require('../mock_data/fitness')
var {data} = require('../mock_data/fitness2')
var MockExample = require('../mock_data/example')
var fs = require('fs')
var hljs = require('highlight.js'); // https://highlightjs.org/
const requestData = {

};
/* GET users listing. */
router.get('/', function (req, res, next) {
  res.send('respond with a resource');
})

router.get('/list', function (req, res, next) {
  res.send(list);
});
router.get('/example', function (req, res, next) {
  res.send(new MockExample().getData());
});
router.post('/api', function (req, res, next) {
  const body = req.body;
  requestData[body.url] = [body.data]
  res.send("ok");
});
router.get('/api/write', function (req, res, next) {
  fs.writeFile('f:/data/fitness_bak.json', JSON.stringify(requestData, null, 2), (err) => {
    res.send("err" + err);
  })

  res.send("ok");
});
for (let dataKey in data) {
  router.get(('/' + dataKey).replace(/\/+/, '/'), function (req, res, next) {
    res.send(data[dataKey]);
  });
}

module.exports = router;
